/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package dgbgui.tools;

import java.util.Set;

import dgbgui.command.Command;
import dgbgui.command.CommandStack;
import dgbgui.command.SetTargetCommand;
import dgbgui.modeldocument.primitives.Concept;
import dgbgui.modeldocument.primitives.Conceptron;
import dgbgui.selection.SelectionManager;

public class SetTargetTool implements Tool {

    public void execute() {
        
        Set<Object> selection = 
            SelectionManager.getInstance().getSelection(Conceptron.class);
        assert(selection.size() == 1);
        Concept concept = (Concept)selection.iterator().next();
        assert(concept != null);
        
        Command command = new SetTargetCommand(concept);
        CommandStack.getInstance().execute(command);
        
        // Also set the concept as the selection, so we can 
        // choose the filtering term in the next step
        
        SelectionManager.getInstance().setSet(Conceptron.class, selection);
                            
    }

}
